const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors')
const app = express();
app.use(cors());
const port = 3000;

// 用于解析 application/json 类型的请求体
app.use(bodyParser.json());

// 假设的个人所得税计算函数
function calculateTax(income) {
  // 这里应包含实际的计算逻辑
            // 以下为示例税率和计算方法
    const taxRate = 0.1; // 假设税率为 10%
       const deductions = 5000; // 假设起征点为 5000 元
            const taxableIncome = Math.max(income - deductions, 0);
            return taxableIncome > 0 ? taxableIncome * taxRate : 0;
}

app.get('/', (req, res) => {
    res.send('12345')
})

// Web 服务端点
app.post('/calculate-tax', (req, res) => {
  const { income } = req.body;
  const tax = calculateTax(income);
  res.json({ tax });
});

app.listen(port, () => {
  console.log(`Tax calculation service listening at http://localhost:${port}`);
});